unit RenameExit;

interface

uses
  Database,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons;

type
  TFormRenameExit = class(TForm)
    Label1: TLabel;
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    EditExit: TEdit;
    procedure EditExitChange(Sender: TObject);
    procedure BtnCancelClick(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure EditExitKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
    ex, map, x, y: string;
  end;

var
  FormRenameExit: TFormRenameExit;

implementation
uses
  DBClient, Variants;

{$R *.DFM}

procedure TFormRenameExit.FormCreate(Sender: TObject);
begin
  ex:='';
end;

procedure TFormRenameExit.EditExitChange(Sender: TObject);
begin
  if length(EditExit.text) > 0 then BtnOK.enabled:=true
  else BtnOK.enabled:=false;
end;

procedure TFormRenameExit.BtnCancelClick(Sender: TObject);
begin
  ex:='';
  close;
end;

procedure TFormRenameExit.EditExitKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key = #13 then begin
    BtnOK.click;
    key:=#0;
  end;
end;

procedure TFormRenameExit.BtnOKClick(Sender: TObject);
var
  didfind: boolean;
  mapid: integer;
begin
  if EditExit.text = '' then begin
    messagedlg('You must enter an exit',mtinformation,[mbok],0);
    EditExit.setfocus;
    exit;
  end;
  if EditExit.text = ex then begin
    messagedlg('That''s the same exit',mtinformation,[mbok],0);
    EditExit.selectall;
    EditExit.setfocus;
    exit;
  end;
  mapid := Datawell.TableMaps.Lookup('map', map, 'map_id');
  didFind := datawell.TableExits.Locate('MAP1;X;Y;FEXIT', VarArrayOf([mapid, x, y, editExit.Text]), []);
  if didFind then begin
    messagedlg('The room already has that exit.',mtinformation,[mbok],0);
    EditExit.selectall;
    EditExit.setfocus;
    exit;
  end;
  ex:=EditExit.text;
  close;
end;

end.
